﻿using System;
using System.IO;
using System.Drawing;

using SharedGenomics.Core;
using SharedGenomics.Workbench.Core;

namespace SharedGenomics.Workbench.Services
{
    public class AnnotationImageUploader : IAnnotationImageUploader
    {
        private readonly IAnnotationSessionService annotationSessionService;

        public AnnotationImageUploader(IAnnotationSessionService annotationService)
        {
            this.annotationSessionService = annotationService;
        }

        public void UploadAnnotationImage(Guid id, Image annotationImage)
        {
            annotationImage.ThrowIfNull("annotationImage");
            MemoryStream ms = new MemoryStream();
            annotationImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byte[] data = ms.ToArray();

            this.annotationSessionService.UploadPng(id, data);
        }
    }
}
